package com.zsrt.cookie;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class SessionServlet extends HttpServlet {

	
	private static final long serialVersionUID = 4518778000254499863L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		HttpSession session=request.getSession();
		String time=null;
		if(session.getAttribute("lasttime")==null){
			time=new Date().toString();
			session.setAttribute("lasttime", time);
			session.setAttribute("currenttime", time);
		}else{
			time=new Date().toString();
			session.setAttribute("lasttime", session.getAttribute("currenttime"));
			session.setAttribute("currenttime", time);
		}
	
		response.sendRedirect(request.getContextPath()+"/session.jsp");
	}
}
